<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>
    <script type="text/javascript" src="./plugins/vue/dist/vue.min.js"></script>
    <script type="text/javascript" src="./plugins/axios/dist/axios.min.js"></script>
    <!--引入公共的js-->
    <script type="text/javascript" src="./js/common.js"></script>
</head>
<body>
<div id="app"></div>
</body>
<script>
    new Vue({
        el: "#app",
        mounted() {
            let param = getParam();
            this.$http.post('/wechat/handlCallback', param).then(res => {
                let {success, message, resultObj} = res.data;
                // console.log(message, success, resultObj)
                //成功且有openid，跳转绑定界面
                if (success && resultObj.openid) {
                    location.href = '/binder.html?openid=' + resultObj.openid;
                    //成功有token
                } else if (success && resultObj.token) {
                    //把token存放到浏览器
                    localStorage.setItem("token", resultObj.token);
                    //把user存放到浏览器
                    localStorage.setItem("user", JSON.stringify(resultObj.user))
                    //跳转到主页面
                    location.href = '/index.html'
                }
            })
        }
    });
</script>
</html>